<template>
  <div>
    <h3 class="h3-title">
      粉丝&nbsp;&nbsp;&nbsp;({{ singerDetails.profile.followeds }})
    </h3>
    <div v-if="singerDetails.profile.followeds > 0" class="content">
      <div class="list" v-for="(item, index) in fansList" :key="index">
        <div class="middle">
          <div class="left">
            <div class="img">
              <img @click="singerInfo(item)" :src="item.avatarUrl" alt="" />
            </div>
            <div class="info">
              <p @click="singerInfo(item)" class="title text-style">
                {{ item.nickname }}
              </p>
              <div class="control">
                <div @click="dynamicInfo(item)" class="text-style">
                  动态<i class="title">{{ item.eventCount }}</i>
                </div>
                <span>|</span>
                <div @click="attentionInfo(item)" class="text-style">
                  关注<i class="title">{{ item.follows }}</i>
                </div>
                <span>|</span>
                <div @click="fansInfo(item)" class="text-style">
                  粉丝<i class="title">{{ item.followeds }}</i>
                </div>
              </div>
              <p class="one-line">{{ item.signature }}</p>
            </div>
          </div>
          <div class="right">
            <button class="white-button">发私信</button>
            <div class="but-text">
              <i class="iconfont weight">&#xe614;</i><span>已关注</span>
            </div>
          </div>
        </div>
      </div>
      <!-- <div class="more" @click="getFansInfo" v-if="more">加载更多</div> -->
    </div>
    <div v-else class="noList">
      <i class="img"></i>
      <span>还没有粉丝</span>
    </div>
  </div>
</template>

<script>
import { userFolloweds } from "@/api";
import { mapGetters } from "vuex";
export default {
  name: "fans",
  data() {
    return {
      fansList: [],
      timeout: null,
      more: true,
      lasttime: "",
    };
  },
  created() {
    this.init();
  },
  mounted() {
    // 接口 lasttime 请求不到数据? 
    // this.$nextTick(() => {
    //   window.addEventListener("scroll", this.debounce(this.handle, 1000));
    // });
  },
  computed: {
    ...mapGetters(["singerDetails"]),
  },
  beforeRouteUpdate(to, form, next) {
    this.init();
    next();
  },
  methods: {
    // debounce(fn, wait) {
    //   this.timeout = null;
    //   return function () {
    //     if (this.timeout !== null) clearTimeout(this.timeout);
    //     this.timeout = setTimeout(fn, wait);
    //   };
    // },
    // handle() {
    //   let scrollTop =
    //     document.body.scrollTop || document.documentElement.scrollTop;
    //   if (document.body.scrollHeight - scrollTop < 1500) {
    //     let lasttime = this.fansList.slice(-1)[0].time;
    //     userFolloweds({
    //       uid: this.$route.query.id,
    //       limit: 10,
    //       lasttime
    //     }).then((data) => {
    //       this.fansList = data.followeds;
    //     });
    //   }
    // },
    init() {
      this.getFansInfo();
    },
    getFansInfo() {
      userFolloweds({
        uid: this.$route.query.id,
        limit: this.singerDetails.profile.followeds || 1,
        lasttime:this.lasttime
      }).then((data) => {
        this.fansList = this.fansList.concat( data.followeds );
        this.lasttime = data.lasttime;
        this.more = data.more;
      });
    },

    singerInfo(val) {
      const { userId } = val;
      this.$router.push({
        name: "userpage",
        query: {
          id: userId,
        },
      });
    },
    dynamicInfo(val) {
      const { userId } = val;
      this.$router.push({
        name: "dynamic",
        query: {
          id: userId,
        },
      });
    },
    attentionInfo(val) {
      const { userId } = val;
      this.$router.push({
        name: "attention",
        query: {
          id: userId,
        },
      });
    },
    fansInfo(val) {
      const { userId } = val;
      this.$router.push({
        name: "fans",
        query: {
          id: userId,
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.more {
  margin-top:20px;
  text-align: center;
  font-size: 12px;
  color: #999;
  cursor: pointer;
}
.noList {
  font-weight: 600;
  height: 359px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 18px;
  font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
  span {
    margin-left: 10px;
  }
  .img {
    background-image: url(../../assets/img/myHomepagefans.png);
    background-position: no-repeat 0 9999px;
    width: 64px;
    height: 50px;
    background-position: 0 -347px;
  }
}
.footer-size {
  text-align: center;
  margin-top: 25px;
}
.content {
  display: flex;
  flex-wrap: wrap;
  .list:nth-of-type(2n) {
    border-left: 0;
  }
  .list {
    box-sizing: border-box;
    width: 50%;
    height: 100px;
    border: 1px solid #d5d5d5;
    border-top: 0;
    padding: 20px;
    display: flex;
    .text-style {
      cursor: pointer;
    }
    .text-style:hover {
      text-decoration: underline;
    }
    .middle {
      font-size: 12px;
      flex: 1;
      display: flex;
      justify-content: space-between;
      .left {
        display: flex;
        width: 360px;
        .img {
          cursor: pointer;
          width: 60px;
          height: 60px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .info {
          color: #666;
          margin-left: 10px;
          width: 280px;
          .title {
            color: #0c73c2;
          }
          .control {
            line-height: 22px;
            display: flex;
            span {
              margin: 0 6px;
            }
          }
        }
      }
      .right {
        text-align: center;
        .white-button {
          width: 66px;
          height: 30px;
          border-radius: 3px;
          cursor: pointer;
        }
        .but-text {
          margin-top: 10px;
          color: #999;
        }
        .weight {
          font-weight: 600;
          margin-right: 4px;
        }
      }
    }
  }
}
.one-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.h3-title {
  font-size: 20px;
  color: #333;
  border-bottom: 2px solid #c20c0c;
}
</style>